home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / shazam11.zip / DEMOSE.INC < prev    next >
Text File  |  1991-11-04  |  11KB  |  277 lines

  1.    {===================================================================
  2.  
  3.    DATA
  4.  
  5.    ===================================================================}
  6. const
  7.    FileSpec                  : string = '*.TXT' ;
  8.    {===================================================================
  9.  
  10.    SEARCH
  11.  
  12.    ===================================================================}
  13. function CreateFindDialog : PDialog ;
  14. var
  15.    D                         : PDialog ;
  16.    Control                   : PView ;
  17.    R                         : TRect ;
  18. begin
  19.    R.Assign ( 0 , 0 , 38 , 12 ) ;
  20.    D                         := New ( PDialog , Init ( R , 'Find' ) ) ;
  21.    with D^ do
  22.    begin
  23.       Options                := Options or ofCentered ;
  24.       R.Assign ( 3 , 3 , 32 , 4 ) ;
  25.       Control                := New ( PInputLine , Init ( R , 80 ) ) ;
  26.       Insert ( Control ) ;
  27.       R.Assign ( 2 , 2 , 15 , 3 ) ;
  28.       Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
  29.       R.Assign ( 32 , 3 , 35 , 4 ) ;
  30.       Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
  31.       R.Assign ( 3 , 5 , 35 , 7 ) ;
  32.       Insert ( New ( PCheckBoxes , Init ( R ,
  33.                NewSItem ( '~C~ase sensitive' ,
  34.                NewSItem ( '~W~hole words only' , NIL ) ) ) ) ) ;
  35.  
  36.       R.Assign ( 14 , 9 , 24 , 11 ) ;
  37.       Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
  38.       Inc ( R.A.X , 12 ) ; 
  39.       Inc ( R.B.X , 12 ) ;
  40.       Insert ( New ( PButton , 
  41.                      Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
  42.       SelectNext ( FALSE ) ;
  43.    end ;
  44.    CreateFindDialog          := D ;
  45. end ;
  46.    {===================================================================
  47.  
  48.    REPLACE
  49.  
  50.    ===================================================================}
  51. function CreateReplaceDialog : PDialog ;
  52. var
  53.    D                         : PDialog ;
  54.    Control                   : PView ;
  55.    R                         : TRect ;
  56. begin
  57.    R.Assign ( 0 , 0 , 40 , 16 ) ;
  58.    D                         := New ( PDialog , Init ( R , 'Replace' ) ) ;
  59.    with D^ do
  60.    begin
  61.       Options                := Options or ofCentered ;
  62.       R.Assign ( 3 , 3 , 34 , 4 ) ;
  63.       Control                := New ( PInputLine , Init ( R , 80 ) ) ;
  64.       Insert ( Control ) ;
  65.       R.Assign ( 2 , 2 , 15 , 3 ) ;
  66.       Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
  67.       R.Assign ( 34 , 3 , 37 , 4 ) ;
  68.       Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
  69.       R.Assign ( 3 , 6 , 34 , 7 ) ;
  70.       Control                := New ( PInputLine , Init ( R , 80 ) ) ;
  71.       Insert ( Control ) ;
  72.       R.Assign ( 2 , 5 , 12 , 6 ) ;
  73.       Insert ( New ( PLabel , Init ( R , '~N~ew text' , Control ) ) ) ;
  74.       R.Assign ( 34 , 6 , 37 , 7 ) ;
  75.       Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 11 ) ) ) ;
  76.  
  77.       R.Assign ( 3 , 8 , 37 , 12 ) ;
  78.       Insert ( New ( PCheckBoxes ,
  79.                   Init ( R ,
  80.                      NewSItem ( '~C~ase sensitive' ,
  81.                      NewSItem ( '~W~hole words only' ,
  82.                      NewSItem ( '~P~rompt on replace' ,
  83.                      NewSItem ( '~R~eplace all' , NIL ) ) ) ) ) ) ) ;
  84.  
  85.       R.Assign ( 17 , 13 , 27 , 15 ) ;
  86.       Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
  87.       R.Assign ( 28 , 13 , 38 , 15 ) ;
  88.       Insert ( New ( PButton , Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
  89.  
  90.       SelectNext ( FALSE ) ;
  91.    end ;
  92.    CreateReplaceDialog       := D ;
  93. end ;
  94.    {===================================================================
  95.  
  96.    EXECUTE
  97.  
  98.    ===================================================================}
  99. function DoEditDialog ( Dialog : integer ; Info : pointer ) : word ; far ;
  100. var
  101.    R                         : TRect ;
  102.    T                         : TPoint ;
  103. begin
  104.    case Dialog of
  105.    edOutOfMemory :
  106.       DoEditDialog           := MessageBox ( 'Not enough memory for this operation.' ,
  107.                                              NIL , mfError + mfOkButton ) ;
  108.    edReadError :
  109.       DoEditDialog           := MessageBox ( 'Error reading file %s.' ,
  110.                                              @Info , mfError + mfOkButton ) ;
  111.     edWriteError :
  112.       DoEditDialog           := MessageBox ( 'Error writing file %s.' ,
  113.                                              @Info , mfError + mfOkButton ) ;
  114.     edCreateError :
  115.       DoEditDialog           := MessageBox ( 'Error creating file %s.' ,
  116.                                              @Info , mfError + mfOkButton ) ;
  117.     edSaveModify :
  118.       DoEditDialog           := MessageBox ( '%s has been modified. Save?' ,
  119.                                              @Info , mfInformation + mfYesNoCancel ) ;
  120.     edSaveUntitled :
  121.       DoEditDialog           := MessageBox ( 'Save untitled file?' ,
  122.                                              NIL , mfInformation + mfYesNoCancel ) ;
  123.     edSaveAs :
  124.       DoEditDialog           := ExecDialog ( New ( PFileDialog , Init ( FileSpec ,
  125.                                              'Save file as' , '~N~ame' , fdOkButton , 101 ) ) , Info ) ;
  126.     edFind :
  127.       DoEditDialog           := ExecDialog ( CreateFindDialog , Info ) ;
  128.     edSearchFailed :
  129.       DoEditDialog           := MessageBox ( 'Search string not found.' ,
  130.                                              NIL , mfError + mfOkButton ) ;
  131.     edReplace :
  132.       DoEditDialog           := ExecDialog ( CreateReplaceDialog , Info ) ;
  133.     edReplacePrompt :
  134.       begin
  135.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  136.    Avoid placing the dialog on the same line as the cursor
  137.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  138.         R.Assign ( 0 , 1 , 40 , 8 ) ;
  139.         R.Move ( ( Desktop^.Size.X - R.B.X ) div 2 , 0 ) ;
  140.         Desktop^.MakeGlobal ( R.B , T ) ;
  141.         Inc ( T.Y ) ;
  142.         if TPoint ( Info ).Y <= T.Y then
  143.            R.Move ( 0 , Desktop^.Size.Y - R.B.Y - 2 ) ;
  144.         DoEditDialog         := MessageBoxRect ( R , 'Replace this occurence?' ,
  145.           NIL , mfYesNoCancel + mfInformation ) ;
  146.       end ;
  147.    end ;
  148. end ;
  149.    {===================================================================
  150.  
  151.    Opens a window, with choice of whether visible
  152.  
  153.    ===================================================================}
  154. function OpenEditor ( FileName : FNameStr ; Visible : boolean ) : PEditWindow ;
  155. var
  156.    P                         : PView ;
  157.    R                         : TRect ;
  158. begin
  159.    DeskTop^.GetExtent ( R ) ;
  160.    P                         := Application^.ValidView (
  161.                                 New ( PEditWindow ,
  162.                                 Init ( R , FileName, wnNoNumber ) ) ) ;
  163.    if not Visible then P^.Hide ;
  164.    DeskTop^.Insert ( P ) ;
  165.    OpenEditor                := PEditWindow ( P ) ;
  166. end ;
  167.    {===================================================================
  168.  
  169.    Use "FindFirst" to test for file.
  170.    Note:  Wildcards return FALSE, though there may be matching files.
  171.  
  172.    ===================================================================}
  173. function Exist ( Path : string ) : boolean ;
  174. var
  175.    SR                        : SearchRec ;
  176. begin
  177.    Exist                     := FALSE ;
  178.    if pos ( '?' , Path ) > 0 then EXIT ;
  179.    if pos ( '*' , Path ) > 0 then EXIT ;
  180.    FindFirst ( Path , AnyFile , SR ) ;
  181.    Exist                     := DosError = 0 ;
  182. end ;
  183.    {===================================================================
  184.  
  185.    Use the "Parse Filename" function of DOS to get a valid drive letter.
  186.    This function does not access the drive.
  187.    NOTE:  Does not correct for "phantom" floppy drives.
  188.  
  189.    ===================================================================}
  190. function IsDosDrive ( DriveNum : byte ) : boolean ;
  191. var
  192.    FCB                       : array [ 1 .. 36 ] of byte ;
  193.    FileName                  : array [ 1 .. 3 ] of char ;
  194.    R                         : registers ;
  195. begin
  196.    IsDosDrive                := FALSE ;
  197.    if DriveNum < 1 then EXIT ;
  198.    if DriveNum > 26 then EXIT ;
  199.    fillchar ( FCB, sizeof ( FCB ), 0 ) ;
  200.    FileName                  := 'x:'#0 ;
  201.    FileName [ 1 ]            := Chr ( DriveNum + 64 ) ;
  202.    with R do
  203.    begin
  204.       AH                     := $29 ;
  205.       AL                     := $00 ;
  206.       DS                     := seg ( FileName ) ;
  207.       SI                     := ofs ( FileName ) ;
  208.       ES                     := seg ( FCB ) ;
  209.       DI                     := ofs ( FCB ) ;
  210.       MsDos ( R ) ;
  211.       if AL = $FF then EXIT ;
  212.    end ;
  213.    IsDosDrive                := TRUE ;
  214. end ;
  215.    {===================================================================
  216.                                                                DOS 3.1+
  217.    IOCTL:  Check if block device is remote.
  218.    NOTE:  DOS returns TRUE, even if the disk number is invalid.
  219.           Use program logic or "IsDosDrive" to avoid invalid disks.
  220.    ===================================================================}
  221. function IsRemote ( DriveNum : byte ) : boolean ;
  222. var
  223.    Regs                      : registers ;
  224. begin
  225.    IsRemote                  := FALSE ;
  226.    Regs.AH                   := $44 ;
  227.    Regs.AL                   := $09 ;
  228.    Regs.BL                   := DriveNum ;
  229.    Regs.DX                   := 0 ;
  230.    MsDos ( Regs ) ;
  231.    if Regs.Flags and FCarry = 0 then
  232.       if ( Regs.DX and $1000 ) <> 0 then   { Bit 12, 0=local 1=remote }
  233.          IsRemote            := TRUE ;
  234. end ;
  235.    {===================================================================
  236.  
  237.    Get AUTOEXEC.BAT and CONFIG.SYS via COMSPEC drive
  238.    Note:  May not be true for networks, if COMSPEC is reset...
  239.  
  240.    ===================================================================}
  241. procedure LoadDosIni ;
  242. var
  243.    BootDir                   : string ;
  244. begin
  245.    BootDir                   := copy ( GetEnv ( 'COMSPEC' ) , 1 , 3 ) ;
  246.    if IsRemote ( Ord ( BootDir[1] ) - 64 ) then EXIT ;
  247.    if exist ( BootDir + 'AUTOEXEC.BAT' ) then
  248.       OpenEditor ( BootDir + 'AUTOEXEC.BAT' , TRUE ) ;
  249.    if exist ( BootDir + 'CONFIG.SYS' ) then
  250.       OpenEditor ( BootDir + 'CONFIG.SYS' , TRUE ) ;
  251. end ;
  252.    {===================================================================
  253.  
  254.    Test for Windows 3.0 directory on C: through Z:, but only load local.
  255.  
  256.    ===================================================================}
  257. procedure LoadWinIni ;
  258. var
  259.    b                         : byte ;
  260.    WinDrive                  : char ;
  261. begin
  262.    for b := 3 to 26 do
  263.    begin
  264.       if IsDosDrive ( b ) then
  265.          if not IsRemote ( b ) then
  266.          begin
  267.             WinDrive            := chr ( b + 64 ) ;
  268.             if exist ( WinDrive + ':\WINDOWS\WIN.INI' ) then
  269.             begin
  270.                OpenEditor ( WinDrive + ':\WINDOWS\WIN.INI' , TRUE ) ;
  271.                OpenEditor ( WinDrive + ':\WINDOWS\SYSTEM.INI' , TRUE ) ;
  272.                EXIT ;
  273.             end ;
  274.          end ;
  275.    end ;
  276. end ;
  277.